package bcit.nxt.mission;

// RoadFollower.java
// One light sensor, one touchsensor
// Follow black road with blue left and yellow right border line

import gin.and.tonic.*;

public class RoadFollower
{
  public RoadFollower()
  {
    
    NxtRobot robot = new NxtRobot();
    Gear gear = new Gear(MotorPort.B,MotorPort.C);
    LightSensor ls = new LightSensor(SensorPort.S3);
    TouchSensor ts = new TouchSensor(SensorPort.S2);
    robot.addPart(gear);
    robot.addPart(ls);
    robot.addPart(ts);
    gear.setSpeed(40);
    ls.activate(true);


     while (true)
    {
      if (ls.getValue() > 400)  //  Bright
        gear.leftArc(0.1);
      else
        gear.rightArc(0.1);

      if (ts.isPressed())
        break;
    }
  

   /* while (true)
    {
      int v = ls.getValue();


      if (v < 390)  // black
      {
        
        System.out.println("v: " + ls.getValue());
        gear.rightArc(0.05);
        
      }
       if (v >=390 && v>420)
       {

          gear.forward();
      }
      if(v>=420)
      {
          System.out.println("v: " + ls.getValue());
          gear.leftArc(0.05);
         
      }
   

      if (ts.isPressed())
        break;
    }*/
    robot.exit();
  }

  public static void main(String[] args)
  {
    new RoadFollower();
  }
}
